package com.intellagric.controller.module.agriecom_produce_category;


import com.intellagric.agriecom.module.agriecom_produce_category.AgriecomProduceCategoryService;
import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.pojo.AgriecomProduceCategory;

import com.intellagric.pojo.SysMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Controller
public class AgriecomProduceCategoryController {
    @Autowired
    private AgriecomProduceCategoryService produceCategoryService;

    @RequestMapping("/produceCategory/add")
    @ResponseBody
    public ResponseMessage addProduceCategory(AgriecomProduceCategory produceCategory){

        //这里的produceCategory需要在前端先给他赋值produce_id
        produceCategory.setId(UUID.randomUUID().toString().replaceAll("-",""));
        produceCategory.setCreateDate(new Date());
        return produceCategoryService.addProduceCategory(produceCategory);
    }

    @RequestMapping("/produceCategory/delete")
    @ResponseBody
    public ResponseMessage deleteProduceCategory(String id){
        return produceCategoryService.deleteProduceCategory(id);
    }


    @RequestMapping("/produceCategory/batchDelete")
    @ResponseBody
    public ResponseMessage batchDeleteProduceCategory(@RequestParam(value="ids[]") String[] ids) {

        return produceCategoryService.batchDeleteProduceCategory(ids);
    }



    @RequestMapping("/produceCategory/edit")
    @ResponseBody
    public ResponseMessage editProduceCategory(AgriecomProduceCategory produceCategory){

        return produceCategoryService.editProduceCategory(produceCategory);
    }

    @RequestMapping("/produceCategory/{id}")
    @ResponseBody
    public AgriecomProduceCategory getProduceCategoryById(@PathVariable String id){
        return produceCategoryService.getProduceCategoryById(id);
    }

    @RequestMapping("/produceCategory/list")
    @ResponseBody
    public LayuiDataGridResult getProduceCategoryList(){
        return produceCategoryService.getProduceCategoryList();
    }

    @RequestMapping("/produceCategory/page")
    @ResponseBody

    public LayuiDataGridResult getProduceCategoryList(int page,int limit){
        return produceCategoryService.getProduceCategoryList(page,limit);
    }

    /**
     * 查询菜单树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/produceCategory/tree")
    @ResponseBody
    public LayuiDataGridResult getTree() {
        return produceCategoryService.getMenu();
    }

    /**
     * 查询菜单树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/produceCategory/treelist")
    @ResponseBody
    public List<AgriecomProduceCategory> getTreeList() {
        LayuiDataGridResult category=produceCategoryService.getMenu();
        return category.getData();
    }


}
